import java.util.*;
public class Main
{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), p = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        int left = 0, right = 0, ret = 0;
        p *= 2;
        while(right < n) {
            while(arr[right] - arr[left] > p)
            {
                left++;
            }
            ret = Math.max(ret, right - left + 1);
            right++;
        }
        System.out.println(ret);
    }
}

